home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / path & frames ƒ / path & frame demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  7.1 KB  |  221 lines  |  [TEXT/KAHL]

  1. /*
  2.     Path & Frame demo 
  3.  
  4.     This application creates 3 shapes: an oval, diamond, and a path which represents an outline of an "E".  We will take these
  5.     3 shapes and combine them into one called - gOvaloidShape. We can combine these shapes by calling AddToShape (..).
  6.     
  7.     Once we have a single gxShape containing the three shapes, we can operate on the properties of these shapes as a single gxShape. 
  8.     By clicking within the content of the window, you can change the following properties: gxColor, pen size, and fill.
  9.     
  10.     NOTES:
  11.     • This file requires the following files to run correctly:
  12.         "graphics shell.c", "Color library.c", "Font library.c", "graphics debug library.c",  "oval library.c", 
  13.         "Shape library.c", "Transform library.c".
  14.  
  15.     • For ideal printing of this file, please print in "landscape".
  16.     
  17.     ©1990 -1994 Apple Computer, Inc.
  18.     All rights reserved.
  19. */
  20.  
  21. #include <Events.h>
  22. #include <Windows.h>
  23.  
  24. #include "Font library.h"
  25. #include "graphics toolbox.h"
  26. #include "graphics libraries.h"
  27. #include "qd library.h"
  28. #include "graphics shell.h"
  29.  
  30. #define kFrameWidth ff(7)
  31.  
  32. //
  33. //  Set up the title and size of the window 
  34. //
  35. Rect     gWindowQDRect  = {50, 20, 450, 600};
  36. Str255     gWindowTitle = "\pPaths & Frames";
  37.  
  38. //
  39. //    If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  40. //    the "debugging" version of the QuickDraw GX init.  If this version of the init is not installed, nothing bad will happen, 
  41. //    but these  functions will not work. 
  42. //
  43. Boolean        gDebugging = true;
  44.  
  45.  
  46. //
  47. //     Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  
  48. //
  49. Boolean        gGiveMeValidation = true;
  50.  
  51.  
  52. //
  53. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  54. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  55. //    With  gGraphicsHeapSize set to 55k, I had 5 free blocks left in the graphics gxHeap. Sounds good to me.
  56. //
  57. long        gGraphicsHeapSize = 55;
  58.  
  59. gxShape     gOvaloidShape;
  60. gxShape     gTextMessageShape;
  61. Boolean     gDrawState = true;
  62.  
  63.  
  64. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  65.  
  66. void DoInitialization(aWindow)
  67. WindowPtr aWindow;
  68. {    gxRectangle     ovalGeometricData = {ff(50), ff(150), ff(150), ff(195)};
  69.     gxShape            diamond, letterE;
  70.     
  71.     InitCommonColors ();
  72.  
  73.     //
  74.     //    Draw a message to the window which tells the user to click within the window for a change.
  75.     //
  76.     gTextMessageShape = GXNewText(35,(unsigned char*)"Click in the window for a change...",  nil);
  77.     SetShapeCommonFont(gTextMessageShape, timesFont);
  78.     GXSetShapeTextSize(gTextMessageShape, ff(20));
  79.     GXMoveShapeTo (gTextMessageShape, ff(165), ff(390)); 
  80.  
  81.     gOvaloidShape = NewOval(&ovalGeometricData);
  82.     GXRotateShape(gOvaloidShape, ff(20), ff(50), ff(150));
  83.  
  84.     diamond = GXNewRectangle(&ovalGeometricData);
  85.     GXRotateShape(diamond, ff(45), ff(20), ff(170));
  86.     AddToShape(gOvaloidShape, diamond);
  87.     
  88.     
  89.     letterE = GXNewText(1,(unsigned char*)"E", nil);
  90.     SetShapeCommonFont(letterE, timesFont);
  91.     GXSetShapeTextSize(letterE, ff(100));
  92.     GXSetShapeType(letterE, gxPathType);
  93.     GXInsetShape(letterE, -ff(5));
  94.     GXSkewShape(letterE, 0, ff(2), 0, 0);
  95.     GXMoveShapeTo(letterE, ff(40), ff(200));
  96.     AddToShape(gOvaloidShape, letterE);
  97.     
  98.     //
  99.     //    We can now dispose of our diamond and letterE shapes becasue they are now part of the 
  100.     //    geometry contained within our "gOvaloidShape" gxShape.
  101.     GXDisposeShape(diamond);
  102.     GXDisposeShape(letterE);
  103. }
  104.  
  105.  
  106.  
  107. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  108.  
  109. void DoDraw(aWindow)
  110. WindowPtr aWindow;
  111. {
  112.     GXDrawShape(gTextMessageShape);
  113.     
  114.     GXMoveShapeTo(gOvaloidShape, ff(25), ff(100));
  115.     
  116.     if (gDrawState) {
  117.         GXSetShapeFill(gOvaloidShape, gxEvenOddFill);
  118.         GXDrawShape(gOvaloidShape);
  119.         
  120.         GXMoveShape(gOvaloidShape, ff(130), ff(-80));
  121.         GXSetShapeFill(gOvaloidShape, gxWindingFill);
  122.         GXDrawShape(gOvaloidShape);
  123.         
  124.         GXMoveShape(gOvaloidShape, ff(130), ff(80));
  125.         GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
  126.         GXDrawShape(gOvaloidShape);
  127.         
  128.         GXMoveShape(gOvaloidShape, ff(130), ff(-80));
  129.         GXSetShapePen(gOvaloidShape, ff(5));
  130.         GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
  131.         GXDrawShape(gOvaloidShape);
  132.     } else {
  133.  
  134.         //
  135.         //  We ignore these notices because we want to change the color, attributes and pen size.  If we did not, nothing
  136.         //    bad would happen, but you would receive the notice. You can ignore _all_ notices or warnings posted.
  137.         //
  138.         GXIgnoreGraphicsNotice(color_already_set);
  139.         GXIgnoreGraphicsNotice(attributes_already_set);
  140.         GXIgnoreGraphicsNotice(pen_already_set);
  141.  
  142.         GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
  143.         GXSetShapeStyleAttributes(gOvaloidShape, gxCenterFrameStyle);
  144.         GXSetShapePen(gOvaloidShape, kFrameWidth);
  145.         SetShapeCommonColor(gOvaloidShape, red);  
  146.         GXDrawShape(gOvaloidShape);
  147.         
  148.         GXSetShapePen(gOvaloidShape, 0);
  149.         SetShapeCommonColor(gOvaloidShape, gxBlack); 
  150.         GXDrawShape(gOvaloidShape);
  151.         
  152.         GXMoveShape(gOvaloidShape, ff(190), ff(-80));
  153.         GXSetShapeStyleAttributes(gOvaloidShape, gxInsideFrameStyle);
  154.         GXSetShapePen(gOvaloidShape, kFrameWidth);
  155.         SetShapeCommonColor(gOvaloidShape, blue);
  156.         GXDrawShape(gOvaloidShape);
  157.         
  158.         GXSetShapePen(gOvaloidShape, 0);
  159.         SetShapeCommonColor(gOvaloidShape, gxBlack);  
  160.         GXDrawShape(gOvaloidShape);
  161.         
  162.         GXMoveShape(gOvaloidShape, ff(190), ff(80));
  163.         GXSetShapeStyleAttributes(gOvaloidShape, gxOutsideFrameStyle);
  164.         GXSetShapePen(gOvaloidShape, kFrameWidth);
  165.         SetShapeCommonColor(gOvaloidShape, green);
  166.         GXDrawShape(gOvaloidShape);
  167.         
  168.         GXSetShapePen(gOvaloidShape, 0);
  169.         SetShapeCommonColor(gOvaloidShape,  gxBlack); 
  170.         GXDrawShape(gOvaloidShape);
  171.  
  172.         //
  173.         //    We need to balance all of our GXIgnoreGraphicsNotice calls with GXPopGraphicsNotice calls,
  174.         //    thereby preventing the notice stack from overflowing.
  175.         GXPopGraphicsNotice(); 
  176.         GXPopGraphicsNotice();
  177.         GXPopGraphicsNotice();
  178.     }
  179. }
  180.  
  181.  
  182. /*------ DoDispose -------------------------------------------------------------------------------------*/
  183.  
  184. void DoDispose(aWindow)
  185. WindowPtr aWindow;
  186. {
  187.     //  
  188.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  189.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  190.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  191.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  192.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  193.     //  
  194.     GXDisposeShape(gOvaloidShape);
  195.     GXDisposeShape(gTextMessageShape);
  196.     GXDisposeShape(gWindowBoundsShape);
  197.     DisposeCommonColors();
  198.        DisposeWindow(aWindow);
  199. }
  200.     
  201.  
  202. /*------ DoClick ---------------------------------------------------------------------------------------*/
  203.  
  204. void DoClick( orgMouseLoc, theWindow )
  205. gxPoint        orgMouseLoc;
  206. WindowPtr     theWindow;
  207. {
  208.     SetPort ( theWindow );
  209.     EraseRect( &theWindow->portRect );
  210.     
  211.     gDrawState = !gDrawState;
  212.     DoDraw( theWindow );
  213. }
  214.  
  215.  
  216. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  217. void DoIdle(aWindow)
  218. WindowPtr aWindow;
  219. {
  220. }
  221.